package com.ty.rank;

import com.alibaba.fastjson.JSON;

/**
 * @author: Troy.Chen(失足程序员, 15388152619)
 * @version: 2021-08-01 22:06
 **/
public class RankBase implements Comparable<RankBase> {

    private volatile long id;
    private volatile long time;
    private volatile long value;
    private volatile int rank;

    public long getId() {
        return id;
    }

    public RankBase setId(long id) {
        this.id = id;
        return this;
    }

    public long getTime() {
        return time;
    }

    public RankBase setTime(long time) {
        this.time = time;
        return this;
    }

    public long getValue() {
        return value;
    }

    public RankBase setValue(long value) {
        this.value = value;
        return this;
    }

    public int getRank() {
        return rank;
    }

    public RankBase setRank(int rank) {
        this.rank = rank;
        return this;
    }

    @Override
    public int compareTo(RankBase o2) {
        final long o1value = this.getValue();
        final long o2value = o2.getValue();
        if (o1value != o2value) {
            return Long.compare(o2value, o1value);
        }
        return Long.compare(this.getTime(), o2.getTime());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        RankBase rankBase = (RankBase) o;

        return id == rankBase.id;
    }

    @Override
    public int hashCode() {
        return (int) (id ^ (id >>> 32));
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
